home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Musique / Quod Libet / quodlibet-3.3.0-installer.exe / bin / quodlibet / mmkeys / pyhook.pyc (.txt) < prev   
Python Compiled Bytecode  |  2014-12-31  |  2KB  |  50 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.7)
  3.  
  4. from gi.repository import GLib
  5. from _base import MMKeysBackend, MMKeysAction, MMKeysImportError
  6.  
  7. try:
  8.     import pyHook
  9. except ImportError:
  10.     raise MMKeysImportError
  11.  
  12.  
  13. class PyHookBackend(MMKeysBackend):
  14.     _EVENTS = {
  15.         'Media_Prev_Track': MMKeysAction.PREV,
  16.         'Media_Next_Track': MMKeysAction.NEXT,
  17.         'Media_Stop': MMKeysAction.STOP,
  18.         'Media_Play_Pause': MMKeysAction.PLAYPAUSE }
  19.     
  20.     def __init__(self, name, callback):
  21.         self._hm = pyHook.HookManager()
  22.         self._hm.KeyDown = self._keyboard_cb
  23.         self._callback = callback
  24.         self._hm.HookKeyboard()
  25.  
  26.     
  27.     def _keyboard_cb(self, event):
  28.         
  29.         def idle_cb(action):
  30.             if not self._callback:
  31.                 return None
  32.             None._callback(action)
  33.             return False
  34.  
  35.         key = event.Key
  36.         if key in self._EVENTS:
  37.             GLib.idle_add(idle_cb, self._EVENTS[key])
  38.         return True
  39.  
  40.     
  41.     def cancel(self):
  42.         if not self._hm:
  43.             return None
  44.         None._hm.UnhookKeyboard()
  45.         self._hm.KeyDown = None
  46.         self._hm = None
  47.         self._callback = None
  48.  
  49.  
  50.